'use strict';
define([
    'angular',
    'routes',
    'dependency',
    'angularLoading',
    'angularResource',
    'angularSanitize',
    'angularRoute',
    'bootstrap',
    'bootstrapDateTimePicker',
    'bootstrapDateTimePickerCN',
    'grumble',
    'iCheck'
], function(angular,config, dependencyResolverFor){
    var app = angular.module('mainApp', [ 'ngResource', 'ngSanitize', 'ngRoute','chieffancypants.loadingBar']);
    app.config(function($routeProvider, $locationProvider, $controllerProvider, $compileProvider, $filterProvider, $provide){
            app.controller = $controllerProvider.register;
            app.directive  = $compileProvider.directive;
            app.filter     = $filterProvider.register;
            app.factory    = $provide.factory;
            app.service    = $provide.service;
            $locationProvider.html5Mode(true);
            if(config.routes !== undefined){
                angular.forEach(config.routes, function(route, path){
                    $routeProvider
                        .when(path, {templateUrl:route.templateUrl, resolve:dependencyResolverFor(route.dependencies)});
                });
            }
            if(config.defaultRoutePath !== undefined){
                $routeProvider.otherwise({redirectTo:config.defaultRoutePath});
            }
        }
    );
    return app;
});
